"""
获取百度热搜的数据，并且发送邮件
"""

from selenium import webdriver
import yagmail
from datetime import datetime
import schedule
import time


wd = webdriver.Chrome()
wd.get("https://www.baidu.com")
eles = []
for j in range(4):
    for i in range(6):
        x = str(i)
        y = '//li[@data-index = "'+x+'"]//span[@class="title-content-title"]'
        ele = wd.find_element_by_xpath(y)
        print(y)
        link = wd.find_element_by_xpath('//li[@data-index = "'+x+'"]/a').get_attribute("href")
        tmp = '<p><a href = "' + link + '">' + ele.text + '</a></p>'
        eles.append(tmp)
    wd.find_element_by_xpath('//span[text() = "换一换"]').click()

yag = yagmail.SMTP(user="291993531@qq.com",password="uodzgdbqetsnbjeh", host="smtp.qq.com")

contents = eles

yag.send("291993531@qq.com", datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M"), contents)


wd.quit()